//
//  PopupPanelView.m
//  PopupPanel
//
//  Created by xuyunan on 11-3-19.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "QuotPopupPanelView.h"
#import "QuotSelectList.h"

@implementation QuotPopupPanelView
@synthesize isOpen;
@synthesize quotList;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
		isOpen = YES;
		rectForOpen = self.frame;
		rectForClose = CGRectMake(rectForOpen.origin.x , rectForOpen.origin.y, rectForOpen.size.width, 0);
		
        self.backgroundColor=[UIColor grayColor];
        [self setAlpha:0.9];
		[self.layer setCornerRadius:10.0];   //设置边角圆滑度
		[self setClipsToBounds:YES];         //content and subviews are clipped to the bounds of the view
        
		[self initForButtons];
    }
    return self;
}

CGFloat btx = 20;
CGFloat bty = 50;
CGFloat btwidth = 60;
CGFloat byheight = 30;

//初始化该view上的button
-(void)initForButtons{
	NSString *buttonName = nil;
	UIButton *button = nil;
	
    //业务员
    buttonName =@"一天";
    button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(btx, bty, btwidth, byheight);
    [button setTitle:buttonName forState:UIControlStateNormal];
    button.tag = 0;
    [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:button];
    bty += 40;

    //客户
    buttonName =@"一周";
    button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(btx, bty, btwidth, byheight);
    [button setTitle:buttonName forState:UIControlStateNormal];
    button.tag = 1;
    [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:button];
    bty += 40;
    
    //我
    buttonName =@"一个月";
    button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(btx, bty, btwidth, byheight);
    [button setTitle:buttonName forState:UIControlStateNormal];
    button.tag = 2;
    [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:button];
    bty += 40;
    
//	bty = 50;//还原
}

-(void)buttonPressed:(UIButton *)button{
	int tag = button.tag;
	NSString *alertMessage = [[NSString alloc] initWithFormat:@" %d 号按钮被按下了...",tag];
	selectIndex = tag;
    [self viewClose];
    NSLog(@"buttonPressed=%@",alertMessage);
	[alertMessage release];
    
    [quotList setSelectDays:@"1"];
    if (selectIndex == 1)
        [quotList setSelectDays:@"7"];
    if (selectIndex == 2)
        [quotList setSelectDays:@"30"];
    
    [quotList.responseParams removeAllObjects];
    [quotList refreshData];
}

-(void)viewOpen{
	isOpen = YES;
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:0.4];
	[UIView setAnimationCurve:UIViewAnimationCurveLinear];
	[self setFrame:rectForOpen];
	[UIView commitAnimations];
}

-(void)viewClose{
	isOpen = NO;
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:0.4];
	[UIView setAnimationCurve:UIViewAnimationCurveLinear];
	[self setFrame:rectForClose];
	[UIView commitAnimations];
}

- (void)drawRect:(CGRect)rect {
    // Drawing code
	//如果要把添加button的这两行代码放到这里，那么drawRect方法只能画出按钮的边框，字体显示不出来
	/*
	[self addSubview:self.button];
	[self addSubview:self.button1];
	*/
}


- (void)dealloc {
    [quotList release];
    [super dealloc];
}

-(int)getSelectIndex
{
    return selectIndex;
}

@end
